package com.agileboot.domain.airport.inspectionCheck.model;

import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.airport.inspectionCheck.db.SirInspectionCheckEntity;
import com.agileboot.domain.airport.inspectionCheck.db.SirInspectionCheckService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class InspectionCheckModelFactory {

    @Qualifier("sirInspectionCheckServiceImpl")
    private final SirInspectionCheckService inspectionCheckService;

    public InspectionCheckModel loadById(Long id) {
        SirInspectionCheckEntity entity = inspectionCheckService.getById(id);
        if (entity == null) {
            throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, id, "检查项");
        }
        return new InspectionCheckModel(entity, inspectionCheckService);
    }

    public InspectionCheckModel create() {
        return new InspectionCheckModel(inspectionCheckService);
    }

}
